package com.example.demo.controller;

import com.example.demo.common.Result;
import com.example.demo.entity.Complaint;
import com.example.demo.pojo.ComplaintDTO;
import com.example.demo.service.AttractionService;
import com.example.demo.service.ComplaintService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpSession;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/complaint")
public class ComplaintController {

    @Resource
    private ComplaintService complaintService;
    @Resource
    private AttractionService attractionService;

    @PostMapping("/list")
    public Result list(@RequestBody ComplaintDTO complaintDTO){
        Integer attractionId = attractionService.selectByAttractionName(complaintDTO.getScene());
        if(attractionId != null){
            complaintDTO.setAttractionId(attractionId);
        }
        PageInfo<Complaint> complainList = complaintService.list(complaintDTO);
        if(complainList != null){
            return Result.success(complainList);
        }
        else {
            return Result.error("投诉列表为空!");
        }
    }

    @PostMapping("/publish")
    public Result publish(@RequestBody ComplaintDTO complaintDTO) {
        if(complaintService.publish(complaintDTO) != 1){
            return Result.error("事件添加失败");
        }
        return Result.success();
    }
}
